package com.lordjoe.collectiveintelligence.svm;

import libsvm.*;

import java.util.*;

/**
 * com.lordjoe.collectiveintelligence.svm.SVMDataSource
 *
 * @author Steve Lewis
 * @date May 25, 2009
 */
public class SVMDataSource implements ISVMDataSource
{
    public static SVMDataSource[] EMPTY_ARRAY = {};
    public static Class THIS_CLASS = SVMDataSource.class;

    private final DataSetType m_Type;
    private final List<ISVMDataItem> m_Items = new ArrayList<ISVMDataItem>();

    public SVMDataSource(DataSetType pType)
    {
        m_Type = pType;
    }

    /**
     * Raw, Training or Production
     *
     * @return
     */
    public DataSetType getType()
    {
        return m_Type;
    }

    /**
     * return the items
     *
     * @return
     */
    public ISVMDataItem[] getDataItems()
    {
        return m_Items.toArray(ISVMDataItem.EMPTY_ARRAY);
    }

    /**
     * return the svm_Nodes from this source
     *
     * @return
     */
    public svm_node[][] getNodes()
    {
        ISVMDataItem[] items = getDataItems();
        svm_node[][] ret = new svm_node[items.length][];
        for (int i = 0; i < items.length; i++) {
            ISVMDataItem item = items[i];
            ret[i] = item.getNodes();
        }
        return ret;
    }

    public void clear() {
        m_Items.clear();
    }

    public void addDataItem(ISVMDataItem added) {
        m_Items.add(added);
    }

    public int getSize() {
       return m_Items.size();
    }
}
